package com.earnings.okhttputils.utils.ui.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.earnings.R;
import com.earnings.okhttputils.utils.OkHttp.OkHttpUtils;
import com.earnings.okhttputils.utils.UrlConstant.YUrlAddress;
import com.earnings.okhttputils.utils.adapter.DetailAdatper;
import com.earnings.okhttputils.utils.adapter.YBaseAdapter;
import com.earnings.okhttputils.utils.bean.DetailData;
import com.earnings.okhttputils.utils.god.GodLeftHandBaseActivity;
import com.earnings.okhttputils.utils.god.Listener.GodOnClickListener;
import com.earnings.okhttputils.utils.https.HttpArrayCallback;
import com.earnings.okhttputils.utils.https.HttpMap;
import com.earnings.okhttputils.utils.ui.dialog.DetailDialog;

import java.util.Calendar;
import java.util.List;
import java.util.Map;


/**
 * 补贴明细
 * Created by Administrator on 2017/5/5 0005.
 */

public class DetailActivity extends GodLeftHandBaseActivity implements YBaseAdapter.setOnClickListener, GodOnClickListener, DetailAdatper.Loadmore {

    private RecyclerView recyclerview;
    private DetailAdatper adatper;
    private DetailDialog detailDialog;
    private HttpMap map;
    private int p = 1;

    @Override
    protected int onCreateLayoutId() {
        return R.layout.activity_detail;
    }

    @Override
    protected void init() {
        map = new HttpMap(this);
        detailDialog = new DetailDialog(this);
        setTitle("补贴明细");
        setTopVisibility(top_img, View.GONE);
        setText(R.id.top_right_tv, "？");
        setOnClickListener(this, R.id.top_right_tv);
        top_img.setVisibility(View.GONE);
        recyclerview=getView(R.id.recyclerview);
        recyclerview.setLayoutManager(new LinearLayoutManager(this));
        adatper = new DetailAdatper(R.layout.item_detail1);
        setRecyclerViewLayoutManager(R.id.recyclerview, new LinearLayoutManager(this)).setAdapter(adatper);
        adatper.setOnItemClickListener(this);
        adatper.setLoadmore(this);
        DetailRequest();

    }

    private void DetailRequest() {
        map.put("p", p + "");
        showProgress();
        OkHttpUtils.post().url(YUrlAddress.DETAIL_URL).params(map).build().execute(new HttpArrayCallback<DetailData>(this) {

            @Override
            public void onSuccess(List<DetailData> object, String msg) {
                p++;
                adatper.setDatas(object);
                dismissProgress();
            }

            @Override
            public void onFail(int code, String msg) {
                dismissProgress();

            }
        });

    }



    @Override
    public void ItemOnClickListener(int position, Object data) {
        //    skipActivity(BillDetailsActivity.class);

    }


    @Override
    public void OnClickListener(View view) {
        detailDialog.show();

    }

    @Override
    public void Load() {
        DetailRequest();
    }
}
